package com.ruoyi.accountant.dao;

import com.ruoyi.accountant.domain.Account;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface AccountDao extends TempDao<Account, Long> {
    /***
     * 根据删除状态查询
     * @param deleted
     * @return
     */
    List<Account> findAllByDeleted(int deleted);

    /***
     * 根据名称查询
     * @param accountName
     * @return
     */
    Account findTop1ByAname(String accountName);

    //    @Query("from Account where aid in (select i.inaccount from Inaccount as i where i.dtype = '收入' group by i.inaccount)")
    @Query("from Account where aid in (select t.inAccount from TransactionDetail as t where t.dtype = '应收款' group by t.inAccount)")
    List<Account> findInaccountByIds();

    @Query("from Account where aid in (select t.inAccount from TransactionDetail as t where t.dtype = '应付款' group by t.inAccount)")
    List<Account> findOutaccountByIds();
}
